package com.wx.datastructure.queue.linked;

import com.wx.datastructure.linked.LinkedList;
import com.wx.datastructure.queue.Queue;

/**
 * @author wx
 * @Description: 线性数据结构-单向链表-队列
 * @date 2018/12/19 001918:29
 */
public class LinkedQueue <E> implements Queue<E> {
    private LinkedList<E> linkedList = new LinkedList<>();

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public void enqueue(E e) {
        linkedList.addLast(e);
    }

    @Override
    public E dequeue() {
        return linkedList.removeFirst();
    }

    @Override
    public E getFront() {
        return linkedList.getFirst();
    }

    @Override
    public String toString() {

        StringBuilder res = new StringBuilder();
        res.append(String.format("Queue: size = %d ", getSize()));
        res.append("front [");
        while (getSize() != 0){
            System.out.println(getSize());
            res.append(this.linkedList.removeFirst());
            if (getSize() != 0) {
                res.append(", ");
            }
        }
        res.append("] tail");
        return res.toString();
    }
}
